﻿//code by Heskey0
//https://space.bilibili.com/455965619
//https://github.com/Heskey0

using System;
using UnityEngine;

namespace Common.Extension
{
    public static class GameObjectExtension
    {
        public static GameObject Instantiate(this GameObject self)
        {
            return GameObject.Instantiate(self);
        }

        public static GameObject DontDestroyOnLoad(this GameObject self)
        {
            self.DontDestroyOnLoad();
            return self;
        }
        
        public static GameObject SetParent(this GameObject self, GameObject parent)
        {
            self.transform.SetParent(parent.transform);
            return self;
        }

        public static void DestroyAllChildren(this GameObject self)
        {
            for (int i = 0; i < self.transform.childCount; i++)
            {
                GameObject.Destroy(self.transform.GetChild(i).gameObject);
            }
        }
    }
}
